<?php 
	namespace Admin\Controller\User;
	use Admin\Controller\Auto\AutoController;
	use Think\Page;
	class UserController extends AutoController{
		
		public function insert(){
			// $data = I('post.');
			$user = D('user');
			$personal = M('personal');
			// var_dump($user->create());
			// $data = I('post.');
			// var_dump(I('post.'));die;
			if(!$user->create()){
				exit($user->getError('aaa'));
			}else{
				$res = $user->add();
				if($res){
					$data['pic']='/public/admin/upload/images/1.jpg';
					$data['uid']=$res;
					$personal->add($data);
					echo 'yes';
				}else{
					echo 'no';
				}
			}
		}
		public function index(){
			$this->display();
		}
		/*
		*	ajax 请求主页数据
		*	功能, 分页搜索
		*/
		public function limit(){
			$user = M('user');
			$where['username'] = array('like',"%".I('get.keyword')."%");
			$where['huishou']=0;
			$count = $user->where($where)->count();
			$num = $count/I('get.mylimit');
			$limit = (I('get.ilimit')-1)*I('get.mylimit');
			// $page = new Page($count,I('get.mylimit'));
			$list = $user->where($where)->order('id')->limit($limit.','.I('get.mylimit'))->select();
			// var_dump($user->_sql());
			$list[count($list)]=ceil($num);
			echo json_encode($list);
		}
		public function del(){
			$res = M('user')->where('id = '.I('get.id'))->save(['huishou'=>'1']);
			if($res){
				echo 'yes';
			}else{
				echo 'no';
			}
		}

		public function edit(){
			$user= M('user');
			$user->create();
			if($user->save()){
				echo 'yes';
			}else{
				echo 'no';
			}
		}

		public function sel(){
			$user = D('user');
			$res = $user->where(['username'=>I('post.username')])->find();
			if($res){
				echo 'no';
			}else{
				echo 'yes';
			}
		}
	}
?>